package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.service.ReportService;
import com.itheima.vo.GetEmpGenderVo;
import com.itheima.vo.GetJobListVo;
import com.itheima.vo.NameValueVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;
    @Override
    public GetJobListVo getExprJob() {
        List<NameValueVo> vo = reportMapper.getExprJob();
        log.info("vo:{}",vo);
        GetJobListVo getJobListVo = new GetJobListVo();
        //要判断当数据库中存在数据的时候才进行分装
        if (!CollectionUtils.isEmpty(vo)){
            List<String> name = new ArrayList<>();
            ArrayList<Integer> value = new ArrayList<>();
            for (NameValueVo nameValueVo : vo) {
                name.add(nameValueVo.getName());
                value.add(nameValueVo.getValue());
            }
            getJobListVo.setJobList(name);
            getJobListVo.setDataList(value);
        }

        return getJobListVo;
    }

    @Override
    public List<GetEmpGenderVo> getEmpGender() {
        List<GetEmpGenderVo> data = reportMapper.getGenderData();
        return data;
    }
}
